package br.com.webcrm.service.impl;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import br.com.webcrm.dao.TelefoneDAO;
import br.com.webcrm.model.Telefone;
import br.com.webcrm.service.TelefoneService;

@Service(value = "telefoneService")
public class TelefoneServiceImpl extends BaseServiceImpl implements TelefoneService, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6420907853114434395L;
	
	@Resource
	private TelefoneDAO telefoneDAO;

	public TelefoneDAO getTelefoneDAO() {
		return telefoneDAO;
	}

	public void setTelefoneDAO(TelefoneDAO telefoneDAO) {
		this.telefoneDAO = telefoneDAO;
	}

	@Override
	public Telefone persistir(Telefone telefone) throws Exception {
		if (telefone.getIdTelefone() == null){
			return this.gravar(telefone);
		}else{
			return this.alterar(telefone);
		}
		
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
	public Telefone gravar(Telefone telefone) throws Exception {		
		return getTelefoneDAO().gravar(telefone);
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
	public Telefone alterar(Telefone telefone) throws Exception {		 
		return getTelefoneDAO().atualizar(telefone);
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
	public List<Telefone> consultarPorIdEntidade(Integer idEntidade)
			throws Exception {		
		return getTelefoneDAO().consultarPorIdEntidade(idEntidade);
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
	public void excluir(Telefone telefone) throws Exception {
		getTelefoneDAO().excluir(telefone);
		
	}
	
	

}
